using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using ShoppingCenter.Backend.Api.Model;
using ShoppingCenter.Backend.Api.Params;
using ShoppingCenter.Backend.Api.Repository;
using ShoppingCenter.Backend.Api.Utils;

namespace ShoppingCenter.Backend.Api.Controllers
{
    [Authorize]
    [ApiController]
    [Route("[controller]")]

    //商场控制器
    public class MallMsgController : ControllerBase
    {
        private IConfiguration _configuration;

        private IRepository<MallMsg> _mallMsgRepository;

        public MallMsgController(IConfiguration configuration, IRepository<MallMsg> mallMsgRepository)
        {
            _configuration = configuration;
            _mallMsgRepository = mallMsgRepository;
        }

        //获取所有商场
        public dynamic Get()
        {
            var currentPage = int.Parse(Request.Query["currentPage"][0]);
            var pageSize = int.Parse(Request.Query["pageSize"][0]);

            // 分页
            var mallMsgs = _mallMsgRepository.Table.ToList().Skip((currentPage - 1) * pageSize).Take(pageSize); ;

            return new
            {
                Code = 1000,
                Data = new
                {
                    Data = mallMsgs,
                    Pager = new { currentPage, pageSize, totalSize = mallMsgs.Count() }
                },
                Msg = "获取所有商场成功"
            };
        }
    }
}